package ml;

import java.io.IOException;


public class ArffFileFormat extends MLFileFormat {

	public ArffFileFormat(String trainingFile, DataModel dm) throws IOException {
		super(trainingFile + ".arff", dm);
		bw.append("@RELATION \"" + dm.getName() + "\"\n\n");
	}

	@Override
	public void writeData() throws IOException {
		bw.append("\n@DATA\n");
		for (FeatureVector fv : dm.getFeatureVectors()) {
			bw.append('{');
			for (Data d : fv.getData()) {
				bw.append(d.getColumn() + " " + d.getValue() + ",");
			}
			bw.append(dm.getNbrFeatures() + " " + fv.getLabel());
			bw.append("}\n");
		}
	}

	@Override
	public void writeFeatures() throws IOException {
		for (String fv : ((BagDataModel) dm).wekaDescription()) {
			bw.append("@ATTRIBUTE " + fv + "\n");
		}
		bw.append("\n");
	}
}
